// pages/index/authoriztion/authoriztion.js
const API = require('../../../utils/api.js');
const app = getApp();
const AJAX = require('../../../utils/ajax.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 判断用户是否授权成功
    isHidden: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    console.log(`当前来到了authoriztion授权页面` + JSON.stringify(app.globalData))
    console.log(`是否有携带参数信息:` + JSON.stringify(options))
    let form = options.form;
    let bookkeepingid = options.bookkeepingid;
    let userId = options.userId;
    let url = "";
    if (app.globalData.token && app.globalData.token !== '') {
      switch (form) {
        case 'bookkeepingDetail':
          console.log(`从模板消息进来的~准备跳转到记账详情去`)
          url = '/pages/index/bookkeepingdetail/bookkeepingdetail?form=index&bookkeepingid=' + bookkeepingid;
          break;
        case 'me':
          console.log(`从模板消息进来的~准备跳转到我的记录去`)
          url =  '/pages/me/me?form=authoriztion&userId=' + userId;
          break;
        default:
          console.log(`匹配不到，跳转到主页`)
          url = '/pages/index/index'
          break;
      }
      console.log(`url:` + url)
      wx.reLaunch({
        url: url
      })
    } else {
      console.log('app还未执行完，需要等待执行完毕')
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.callback = res => {
        console.log('执行成功啦！....')
        switch (form) {
          case 'bookkeepingDetail':
            console.log(`从模板消息进来的~准备跳转到记账详情去`)
            url = '/pages/index/bookkeepingdetail/bookkeepingdetail?form=index&bookkeepingid=' + bookkeepingid;
            break;
          case 'me':
            console.log(`从模板消息进来的~准备跳转到我的记录去`)
            url = '/pages/me/me?form=authoriztion&userId=' + userId;
            break;
          default:
            console.log(`匹配不到，跳转到主页`)
            url = '/pages/index/index'
            break;
        }
        console.log(`url:` + url)
        wx.reLaunch({
          url: url
        })
      }
    }

  }
})